package com.authorization.project.authorization.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.authorization.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.authorization.project.authorization.mapper.AuthorizationTokenMapper;
import com.authorization.project.authorization.domain.AuthorizationToken;
import com.authorization.project.authorization.service.IAuthorizationTokenService;

/**
 * 授权tokenService业务层处理
 * 
 * @author 李晓雷
 * @date 2020-05-09
 */
@Service
public class AuthorizationTokenServiceImpl implements IAuthorizationTokenService 
{
    @Autowired
    private AuthorizationTokenMapper authorizationTokenMapper;

    /**
     * 查询授权token
     * 
     * @param id 授权tokenID
     * @return 授权token
     */
    @Override
    public AuthorizationToken selectAuthorizationTokenById(Long id)
    {
        return authorizationTokenMapper.selectAuthorizationTokenById(id);
    }

    /**
     * 查询授权token列表
     * 
     * @param authorizationToken 授权token
     * @return 授权token
     */
    @Override
    public List<AuthorizationToken> selectAuthorizationTokenList(AuthorizationToken authorizationToken)
    {
        return authorizationTokenMapper.selectAuthorizationTokenList(authorizationToken);
    }

    /**
     * 新增授权token
     * 
     * @param authorizationToken 授权token
     * @return 结果
     */
    @Override
    public int insertAuthorizationToken(AuthorizationToken authorizationToken)
    {
        authorizationToken.setCreateTime(DateUtils.getNowDate());
        return authorizationTokenMapper.insertAuthorizationToken(authorizationToken);
    }

    /**
     * 修改授权token
     * 
     * @param authorizationToken 授权token
     * @return 结果
     */
    @Override
    public int updateAuthorizationToken(AuthorizationToken authorizationToken)
    {
        authorizationToken.setUpdateTime(DateUtils.getNowDate());
        return authorizationTokenMapper.updateAuthorizationToken(authorizationToken);
    }

    /**
     * 批量删除授权token
     * 
     * @param ids 需要删除的授权tokenID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationTokenByIds(Long[] ids)
    {
        return authorizationTokenMapper.deleteAuthorizationTokenByIds(ids);
    }

    /**
     * 删除授权token信息
     * 
     * @param id 授权tokenID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationTokenById(Long id)
    {
        return authorizationTokenMapper.deleteAuthorizationTokenById(id);
    }

    /**
     * 验证token
     * @param token
     * @return
     */
    @Override
    public int verifyToken(String token) {
        return authorizationTokenMapper.verifyToken(token);
    }

    /**
     * 根据token查询用户名称
     * @param token
     * @return
     */
    @Override
    public String selectUserNameByToken(String token) {
        return authorizationTokenMapper.selectUserNameByToken(token);
    }


}
